# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=qt3dstudio
pkgbase=mingw-w64-${_realname}-git
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}-git"
_base_ver=1.0.0
pkgver=1.0.0.r249.2afc1a1
pkgrel=1
pkgdesc='3D tool for Qt ecosystem (mingw-w64)'
url='https://www.qt.io/'
arch=('any')
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-qt5"
         "${MINGW_PACKAGE_PREFIX}-gcc"
         "${MINGW_PACKAGE_PREFIX}-make")
makedepends=("git" "perl")
options=('docs' 'staticlibs' '!debug')
source=(${_realname}::git+https://codereview.qt-project.org/qt3dstudio/qt3dstudio#branch=1.0
        ${_realname}/src/3rdparty/ColladaDOM::git+https://codereview.qt-project.org/qt3dstudio/qt3dstudio-collada-dom
        ${_realname}/src/3rdparty/EASTL::git+https://codereview.qt-project.org/qt3dstudio/qt3dstudio-eastl
        ${_realname}/src/3rdparty/Lua::git+https://codereview.qt-project.org/qt3dstudio/qt3dstudio-lua
        ${_realname}/src/3rdparty/pcre::git+https://codereview.qt-project.org/qt3dstudio/qt3dstudio-pcre
        0001-Fix-building-Qt3DStudio-with-mingw.patch
        0002-Use-pragma-directives-only-for-MSVC-builds.patch
        0003-Fix-install-locations.patch
        0020-Fix-warnings-and-building-colladadom-for-mingw.patch
        0021-Build-lua-as-static-library.patch)
sha256sums=('SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            'SKIP'
            '771a3426ab710bb6a324b839281f5e2c63676a1ed949ffea19fcfaa47ae3f8ed'
            '9240fbd8d1f8de5fc732071910ced18102ae05f475e19645907a7bfb37d63cd8'
            '4bbd77a8718d73e7a31d00a5cf436cfc7d4eb49b7a8552b0f0fdc6a1197109ef'
            'f49d42fa7cb727eee3246e7c65eaea5a424db96f4dae6f4af96973b951f29fca'
            '40ba0d169a18bc075d7c7eb24b5afdb2b3599bc64b64e32a27d8a270950c3b7a')

pkgver() {
  cd "${_realname}"

  local full_version=${_base_ver}.r$(git rev-list --count --first-parent HEAD ).$(git rev-parse --short HEAD )

  printf "%s" $full_version
}

prepare() {
  mv ${srcdir}/ColladaDOM ${srcdir}/${_realname}/src/3rdparty/
  mv ${srcdir}/EASTL ${srcdir}/${_realname}/src/3rdparty/
  mv ${srcdir}/Lua ${srcdir}/${_realname}/src/3rdparty/
  mv ${srcdir}/pcre ${srcdir}/${_realname}/src/3rdparty/

  cd ${srcdir}/${_realname}
  patch -p1 -i ${srcdir}/0001-Fix-building-Qt3DStudio-with-mingw.patch
  patch -p1 -i ${srcdir}/0002-Use-pragma-directives-only-for-MSVC-builds.patch
  patch -p1 -i ${srcdir}/0003-Fix-install-locations.patch
  pushd src/3rdparty/ColladaDOM
    patch -p1 -i ${srcdir}/0020-Fix-warnings-and-building-colladadom-for-mingw.patch
  popd
  pushd src/3rdparty/Lua
    patch -p1 -i ${srcdir}/0021-Build-lua-as-static-library.patch
  popd
}

build() {
  local _config_variant=release
  if check_option "debug" "y"; then
    _config_variant=debug
  fi

  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir ${srcdir}/build-${MINGW_CHOST}

  cd ${srcdir}/build-${MINGW_CHOST}
  ${MINGW_PREFIX}/bin/qmake.exe ${srcdir}/${_realname}/qt3dstudio.pro CONFIG+=${_config_variant}
  make ${_config_variant}
  make ${_config_variant} docs
}

package() {
  local _config_variant=release
  if check_option "debug" "y"; then
    _config_variant=debug
  fi

  cd ${srcdir}/build-${MINGW_CHOST}
  make ${_config_variant} INSTALL_ROOT="${pkgdir}${MINGW_PREFIX}" install
  #make ${_config_variant} INSTALL_ROOT="${pkgdir}${MINGW_PREFIX}" install_docs

  cp -rf include ${pkgdir}${MINGW_PREFIX}/
  
  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/qt5/doc
  cp -rf qml ${pkgdir}${MINGW_PREFIX}/share/qt5/
  
  cp -f doc/qt3dstudio.qch ${pkgdir}${MINGW_PREFIX}/share/qt5/doc/
}
